﻿using APIShoppingSystem.Model;
using APIShoppingSystem.Models.EvaluateInfoModel;
using IShoppingBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APIShoppingSystem.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class EvaluateInfoController : ControllerBase
	{
		private IEvaluateInfoBll _evaluateInfoBll;
		public EvaluateInfoController(IEvaluateInfoBll evaluateInfoBll)
		{
			_evaluateInfoBll = evaluateInfoBll;
		}

        /// <summary>
        /// 分页显示、模糊查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="CommodityName"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult EvaluateInfoList(int page, int limit, string CommodityName)
        {
            int count;
            object commodityInfos = _evaluateInfoBll.GetEvaluateInfoList(page, limit, out count, CommodityName);

            return new JsonResult(new
            {
                code = 0,
                msg = "成功",
                count = count,
                data = commodityInfos
            });
        }


        /// <summary>
        /// 添加商品评论
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddEvaluateInfo([FromForm] AddEvaluateInfoModels model)
        {
            CustomActionResult res = new CustomActionResult();

            bool isSuccess = _evaluateInfoBll.AddEvaluate(model.orderId, model.Content, model.State);
            if (isSuccess)
            {
                res.IsSuccess = true;
                res.Status = 1;
                res.Msg = "成功";
            }
            return new JsonResult(res);
        }

        /// <summary>
        /// 删除评论
        /// </summary>
        /// <param name="EvaluateId"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DelEvaluateInfo([FromForm] string EvaluateId)
        {
            CustomActionResult res = new CustomActionResult();
            bool isSuccess = _evaluateInfoBll.Delete(EvaluateId);
            if (isSuccess)
            {
                res.Status = 1;
                res.IsSuccess = true;
                res.Msg = "成功";
            }
            return new JsonResult(res);

        }
    }
}
